<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class AdvType extends Model
{
    use SoftDeletes;
    protected $table = 'adv_types';

    /**
     * 定义主键
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 禁止批量赋值的字段
     *
     * @var array
     */
    protected $guarded = ['id','created_at','deleted_at'];

    /**
     * 软删除应该被调整为日期的属性
     * [$dates description]
     * @var [type]
     */
    protected $dates=[
        'created_at', 'updated_at','deleted_at'
    ];

    protected $appends = ['adv_img_url'];

    public function getAdvImgUrlAttribute()
    {
        return config('app.img_url') . $this->adv_img;
    }


    /*
     * 是否判断地区id
     * */
    public static function adv_region_check($adv_type_id){
        $res = self::where('id',$adv_type_id) -> first();
        if($res){
            return $res -> region_id ?: false;
        }else{
            return false;
        }
    }
}
